package com.kailong.servlet.student;

import com.kailong.dao.admin.ManageStudentDao;
import com.kailong.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/studentRegister")
public class StudentRegister extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String sno = req.getParameter("userid");
        String sname = req.getParameter("sname");
        String ssex = req.getParameter("sex");
        String sphoneNumber = req.getParameter("sphoneNumber");
        String sclass = req.getParameter("sclass");
        String smajor = req.getParameter("smajor");
        String password = req.getParameter("password");
        String scollege = req.getParameter("scollege");
        Student student = new Student(sno,sname,ssex,sphoneNumber,sclass,smajor,scollege,password);
        int count = ManageStudentDao.insert(student);
        if(count>0){
            PrintWriter out = resp.getWriter();
            out.print("<script>");
            out.print("alert('用户注册成功！');");
            out.print("location.href='index.jsp';");
            out.print("</script>");
            out.close();
        }else {
            PrintWriter out = resp.getWriter();
            out.print("<script>");
            out.print("alert('用户注册失败！');");
            out.print("location.href='index.jsp';");
            out.print("</script>");
            out.close();
        }

    }
}
